package com.yztc.youbadbad.presenter;

import com.yztc.youbadbad.model.IOtherModel;
import com.yztc.youbadbad.model.OtherModelImpl;
import com.yztc.youbadbad.ui.homepage.interfaces.IOtherView;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Tiffany.V.Chou on 2016/11/17.
 */

public class OtherPresenterImpl  implements IOtherPresenter{
    private IOtherModel iOtherModel = null;
    private IOtherView iOtherView = null;

    public OtherPresenterImpl(IOtherView iOtherView) {
        this.iOtherView = iOtherView;
        this.iOtherModel = new OtherModelImpl();
    }

    @Override
    public void getOtherInternetData(int path2) {
        iOtherModel.getOtherObservable(path2)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        iOtherView.hideProgressBar();
                    }

                    @Override
                    public void onError(Throwable e) {
                        iOtherView.hideProgressBar();
                        iOtherView.showErrorMessage();
                    }

                    @Override
                    public void onNext(String s) {
                        iOtherView.getOtherInternetData(s);
                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        iOtherView.showProgressBar();
                    }
                });
    }

    @Override
    public void getOther2InternetData(int path2) {
        iOtherModel.getOther2Observable(path2)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        iOtherView.hideProgressBar();
                    }

                    @Override
                    public void onError(Throwable e) {
                        iOtherView.showErrorMessage();
                        iOtherView.hideProgressBar();
                    }

                    @Override
                    public void onNext(String s) {
                        iOtherView.getOther2InternetData(s);
                    }

                    @Override
                    public void onStart() {
                        super.onStart();
                        iOtherView.showProgressBar();
                    }
                });
    }
}
